package com.tl.commonlibrary.ui.beans;

import android.text.TextUtils;

import java.io.Serializable;
import java.util.List;

/**
 * Created by JongSung on 18/3/6.
 */

public class ExerciseBean implements Serializable {
    //题目类型 0 未分类 1 单选，2 多项，3 判断题 4 简答题 5 案例分析题  6 文件筐测试 7计算题
    public static final int TYPE_UNKOWN = 0;
    public static final int TYPE_SINGLE_CHOOSE = 1;
    public static final int TYPE_MULTIPLE_CHOOSE = 2;
    public static final int TYPE_JUDGEMENT_CHOOSE = 3;
    public static final int TYPE_SHORT_ANSWER = 4;
    public static final int TYPE_CASE_ANALYSIS = 5;
    public static final int TYPE_CALCULATION = 7;
    public static final int TYPE_IN_TRAY = 6;


    public static final int TYPE_COLLECTION = 1;
    public static final int TYPE_UN_COLLECTION = 0;
    public static final int DISPLAY_MODE_ANSWERING = 1;//正在答题
    public static final int DISPLAY_MODE_ANALYSIS = 2;//正在查看解析
    public static final int DISPLAY_MODE_ANALYSIS_MARK = 3;//正在查看解析并可主动评分

    public static final int ANSWER_RESULT_UNKOWN = 0;//未答题
    public static final int ANSWER_RESULT_RIGHT = 1;//答题正确
    public static final int ANSWER_RESULT_WRONG = 2;//答题错误


    /**
     * difficulty : 4
     * itemId : 2
     * itemIndex : 1
     * itemQuest : 湖南省会城市是长沙？
     * itemTotal : 20
     * itemType : 3
     * options : [{"desc":"正确","id":"T"},{"desc":"错误","id":"F"}]
     */

    private int difficulty;
    private int itemId;
    private int itemIndex;
    private String itemQuest;
    private int itemTotal;
    private int itemType;
    private List<ExerciseOption> options;
    private double score;
    private int userLike;
    private String answer;
    private String analysis;
    private String userAnswer = "";
    /**
     * 0 未判断结果，1 正确 2错误
     */
    private int userAnswerResult = ANSWER_RESULT_UNKOWN;
    //-----------------------native property ---------------------
    private boolean answered = false;//是否已经填写答案
    private double myScore = Integer.MIN_VALUE;//自评分
    private int displayMode = DISPLAY_MODE_ANSWERING;//ui展示模式

    public int getDifficulty() {
        return difficulty;
    }

    public void setDifficulty(int difficulty) {
        this.difficulty = difficulty;
    }

    public int getItemId() {
        return itemId;
    }

    public void setItemId(int itemId) {
        this.itemId = itemId;
    }

    public int getItemIndex() {
        return itemIndex;
    }

    public void setItemIndex(int itemIndex) {
        this.itemIndex = itemIndex;
    }

    public String getItemQuest() {
        return itemQuest;
    }

    public void setItemQuest(String itemQuest) {
        this.itemQuest = itemQuest;
    }

    public int getItemTotal() {
        return itemTotal;
    }

    public void setItemTotal(int itemTotal) {
        this.itemTotal = itemTotal;
    }

    public int getItemType() {
        return itemType;
    }

    public void setItemType(int itemType) {
        this.itemType = itemType;
    }

    public List<ExerciseOption> getOptions() {
        return options;
    }

    public void setOptions(List<ExerciseOption> options) {
        this.options = options;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    public boolean isUnkown() {
        return itemType == TYPE_UNKOWN;
    }

    public boolean isSingleChoose() {
        return itemType == TYPE_SINGLE_CHOOSE;
    }

    public boolean isMultipleChoose() {
        return itemType == TYPE_MULTIPLE_CHOOSE;
    }

    public boolean isJudgementChoose() {
        return itemType == TYPE_JUDGEMENT_CHOOSE;
    }

    public boolean isShortAnswer() {
        return itemType == TYPE_SHORT_ANSWER;
    }

    public boolean isSubjective() {
        return itemType == TYPE_SHORT_ANSWER || itemType == TYPE_CALCULATION || itemType == TYPE_IN_TRAY || itemType == TYPE_CASE_ANALYSIS;
    }

    public boolean isCaseAnalysis() {
        return itemType == TYPE_CASE_ANALYSIS;
    }

    public boolean isCalculation() {
        return itemType == TYPE_CALCULATION;
    }

    public boolean isInTray() {
        return itemType == TYPE_IN_TRAY;
    }

    public int getUserLike() {
        return userLike;
    }

    public void setUserLike(int userLike) {
        this.userLike = userLike;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    public String getAnalysis() {
        return analysis;
    }

    public void setAnalysis(String analysis) {
        this.analysis = analysis;
    }

    public String getUserAnswer() {
        return userAnswer;
    }

    public void setUserAnswer(String userAnswer) {
        this.userAnswer = userAnswer;
    }

    public int getDisplayMode() {
        return displayMode;
    }

    public void setDisplayMode(int displayMode) {
        this.displayMode = displayMode;
        if (displayMode == DISPLAY_MODE_ANALYSIS) {
            if (isSingleChoose() || isJudgementChoose()) {
                if (!TextUtils.isEmpty(userAnswer)) {
                    for (ExerciseOption op : options) {
                        if (userAnswer.equals(op.getId())) {
                            op.setChecked(true);
                            break;
                        }
                    }
                }
            } else if (isMultipleChoose()) {
                if (!TextUtils.isEmpty(userAnswer)) {
                    for (ExerciseOption op : options) {
                        if (userAnswer.equals(op.getId())) {
                            op.setChecked(true);
                        }
                    }
                }
            }
        }
    }

    public int getUserAnswerResult() {
        return userAnswerResult;
    }

    public void setUserAnswerResult(int userAnswerResult) {
        this.userAnswerResult = userAnswerResult;
    }

    public double getMyScore() {
        return myScore;
    }

    public void setMyScore(double myScore) {
        this.myScore = myScore;
    }

    public boolean hasMyScore() {
        return myScore != Integer.MIN_VALUE;
    }

    public boolean isUserLike() {
        return userLike == TYPE_COLLECTION;
    }

    public boolean isUserUnLike() {
        return userLike == TYPE_UN_COLLECTION;
    }

    public void resetUserLike() {
        if (userLike == TYPE_COLLECTION) {
            userLike = TYPE_UN_COLLECTION;
        } else if (userLike == TYPE_UN_COLLECTION) {
            userLike = TYPE_COLLECTION;
        }
    }

    public boolean isAnswered() {
        return answered;
    }

    public void setAnswered(boolean answered) {
        this.answered = answered;
    }

    public boolean answerRight() {
        return userAnswerResult == ANSWER_RESULT_RIGHT;
    }

    public boolean answerWrong() {
        return userAnswerResult == ANSWER_RESULT_WRONG;
    }

    public boolean hasAnswer() {
        return !TextUtils.isEmpty(userAnswer);
//
//        if (options == null || options.isEmpty()) {
//            return false;
//        }
//        for (int i = 0; i < options.size(); i++) {
//            if (options.get(i).isChecked()) {
//                return true;
//            }
//        }
//        return false;
    }

}
